package info.wangyuan.agent.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import info.wangyuan.agent.config.properties.VectorStoreProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 向量数据持久化存储配置
 *
 * @author Albert
 * @since 2025-07-22 18:43:22
 */
@Configuration
public class EmbeddingStoreConfig {

    private final VectorStoreProperties vectorStoreProperties;

    public EmbeddingStoreConfig(VectorStoreProperties vectorStoreProperties) {
        this.vectorStoreProperties = vectorStoreProperties;
    }

    /**
     * 向量化存储配置
     */
    @Bean
    public EmbeddingStore<TextSegment> initEmbeddingStore() {
        return PgVectorEmbeddingStore.builder()
                .createTable(false)
                .dropTableFirst(false)
                .host(vectorStoreProperties.getHost())
                .port(vectorStoreProperties.getPort())
                .user(vectorStoreProperties.getUser())
                .table(vectorStoreProperties.getTable())
                .password(vectorStoreProperties.getPassword())
                .database(vectorStoreProperties.getDatabase())
                .dimension(vectorStoreProperties.getDimension())
                .build();
    }
}
